
const express = require('express');

const Wechat = require('wechat-jssdk');
const wx = new Wechat({
    appId: 'wxcc738f5fa8bf5585',
    appSecret: '2c2fa9f5a8df267f5f5ba5373fb60912'
});

const app = express();

app.listen(3000);

app.set('view engine', 'xtpl');

app.set('views', 'view');

app.use(express.static('public'));

// 路由
app.get('/', (req, res) => {

    let url = `${req.protocol}://${req.host}${req.url}`;

    // console.log(url);

    // jssdk 认证
    wx.jssdk.getSignature(url).then(signature => {
        // 渲染页面
        console.log(signature);
        res.render('index', signature);
    }).catch((err) => {
        console.log(err)
        res.render('index', {});
    });
});